<?php

namespace app\modules\Admin\models;

use Yii;

/**
 * This is the model class for table "user".
 *
 * @property int $id
 * @property int $schoolid 学号
 * @property int $age 年龄
 * @property string $password 密码
 * @property int|null $sex 性别
 * @property string $classname
 * @property string|null $sign 1正常  2禁用
 * @property string|null $create_time
 * @property string|null $updated_at
 */
class User extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'user';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['schoolid', 'name','age', 'password', 'classname','pinyin'], 'required'],
            [['schoolid', 'age', 'sex','stop'], 'integer'],
            [['create_time', 'updated_at'], 'safe'],
            [['name','password', 'classname','pinyin'], 'string', 'max' => 45],
            [['sign'], 'string', 'max' => 1000],
            [['schoolid'], 'unique'],
        ];
    }

    // 保存前处理
    public function beforeSave($insert) {//{{{

        if($insert){
            $this->create_time = date("Y-m-d H:i:s");
        }
        return parent::beforeSave($insert);
    }//}}}

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'schoolid' => '学号',
            'name' => '姓名',
            'pinyin' => '拼音',
            'age' => '年龄',
            'password' => '密码',
            'sex' => '性别',
            'classname' => '班级',
            'sign' => '信息',
            'stop' => '禁言',
            'create_time' => '注册时间',
            'updated_at' => '更新时间',
        ];
    }
}
